Skip to content

Split JakartaStatement from JakartaQuery, &c. - #1229

Merged
gavinking merged 7 commits into
jakartaee:mainfrom
gavinking:split-static-query-annotations
Nov 23, 2026
Merged

gavinking merged 7 commits into
jakartaee:mainfrom
gavinking:split-static-query-annotations

Conversation

@gavinking

Copy link
Copy Markdown
Member

In #1220, @njr-11 asked for the ability to distinguish queries from statements in the "static" query annotations. Here's how we can do that in a way that's consistent with the other APIs. This adds some complexity which I had been hoping to avoid (three new annotations!) but it really is much more consistent and arguably somewhat more understandable.

I had hoped to not have to introduce changes like this so late in the game but here we are. It's better we find out about this stuff now.

@gavinking

Copy link
Copy Markdown
Member Author

@yrodiere yrodiere left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposal itself, independently from downstream usage, makes sense.

But damn, it's an inconvenient time for this.

If this goes through:

  1. Sooner is better than later. I won't go into details, but breaking this before the end of January would be much more manageable on the Quarkus side, and for Hibernate ORM who's taken some stability commitments.
  2. Do you think we could preserve the "lenient" behavior (perhaps with warnings) of allowing INSERT/UPDATE/DELETE in @NativeQuery/@JakartaQuery on the implementation side with a feature flag? I'm asking the hibernate-processor contributor about complexity, not the spec lead about whether it's allowed, since I know implementations can do whatever they want with feature flags.

Comment on lines +87 to +88
* {@code jakarta.data.repository.Query} as a synonym for this annotation
* when it specifies an {@code UPDATE} or {@code DELETE} statement.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not INSERT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jakarta Query (JPQL) has no INSERT. See jakartaee/query#123.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I guess the fate of INSERT in this case is implementation-dependent then.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, everything to do with INSERT is implementation dependent because it's a Hibernate-only feature ... so ... yeah.

@gavinking gavinking linked an issue Nov 20, 2026 that may be closed by this pull request
@gavinking

Copy link
Copy Markdown
Member Author

Do you think we could preserve the "lenient" behavior

We can certainly preserve it in Hibernate.

@marko-bekhta marko-bekhta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for the split 🙂 👍🏻

* backed by Jakarta Persistence.
* </ul>
* <p> The return type of the method must be {@code void}, {@code int},
* or {@code long}. The parameter types of the method must agree with the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Statement's execute returns int so we allow for long just to "store" those int values, right ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jakarta Data allows long here. Just in case you're updating more than 2 billion rows in one statement :-)

@sebersole

Copy link
Copy Markdown
Contributor

Unfortunate for certain reasons, but not against it.

@njr-11 njr-11 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good and I think the separate between QueryOptions and StatementOptions worked out nicely as well. I added two minor and optional suggestion comments.

@njr-11

njr-11 commented Nov 20, 2026

Copy link
Copy Markdown
Member

2. Do you think we could preserve the "lenient" behavior (perhaps with warnings) of allowing INSERT/UPDATE/DELETE in @NativeQuery/@JakartaQuery on the implementation side

If Jakarta Persistence providers are allowed to handle UPDATE/DELETE via @NativeQuery, it would defeat the purpose of this PR, which gives Jakarta Data providers a way to identify whether to use a Statement vs a TypedQuery to run the query.

Co-authored-by: Nathan Rauh <nathan.rauh@us.ibm.com>
@gavinking

Copy link
Copy Markdown
Member Author
  1. Do you think we could preserve the "lenient" behavior (perhaps with warnings) of allowing INSERT/UPDATE/DELETE in @NativeQuery/@JakartaQuery on the implementation side

If Jakarta Persistence providers are allowed to handle UPDATE/DELETE via @NativeQuery, it would defeat the purpose of this PR, which gives Jakarta Data providers a way to identify whether to use a Statement vs a TypedQuery to run the query.

He's just concerned about Quarkus.

@yrodiere

yrodiere commented Nov 20, 2026 •

Copy link
Copy Markdown
  1. Do you think we could preserve the "lenient" behavior (perhaps with warnings) of allowing INSERT/UPDATE/DELETE in @NativeQuery/@JakartaQuery on the implementation side

If Jakarta Persistence providers are allowed to handle UPDATE/DELETE via @NativeQuery, it would defeat the purpose of this PR, which gives Jakarta Data providers a way to identify whether to use a Statement vs a TypedQuery to run the query.

He's just concerned about Quarkus.

Yeah I'm talking about a temporary, implementation-specific, opt-in flag to preserve backwards compatibility in Quarkus. Obviously it'd have to be removed rather quickly.

@gavinking

Copy link
Copy Markdown
Member Author

OK, so I have not heard any objection to this, and I see that @njr-11 just opened a PR to align Jakarta Data with this work. So bombs away.

@gavinking
gavinking merged commit 51b694f into jakartaee:main Nov 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@JakartaStatement, @NativeStatement, @StatementOptions

5 participants